package com.ding.add;

import java.util.concurrent.CountDownLatch;

/**
 * @author ding
 * @date 2021/7/17 21:21
 * 计数器
 */


public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {

        //总数是6，必须要执行任务的时候，再使用
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 0; i < 6; i++) {

            new Thread(()->{
                countDownLatch.countDown(); //数量减一
                System.out.println(Thread.currentThread() + "gas go");
            },String.valueOf(i)).start();
        }
        countDownLatch.await(); //等待计数器归零
        System.out.println("==========");
    }
}
